package com.cha.chaApp.vaccination.service.impl;


import com.cha.chaApp.vaccination.dao.VaccinationTypeDao;
import com.cha.chaApp.vaccination.param.VaccinationTypeParam;
import com.cha.chaApp.vaccination.service.VaccinationTypeService;
import com.cha.chaCommon.core.entity.hgq.VaccinationType;
import com.cha.chaCommon.redis.utils.RedisUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class VaccinationTypeServiceImpl implements VaccinationTypeService {
    @Resource
    private VaccinationTypeDao vaccinationTypeDao;


    @Override
    public List<VaccinationType> selectAllVaccinationTypeById() {
        String key = "Vaccination:type";
        List<VaccinationType> list = (List<VaccinationType>) RedisUtils.getValue(key);
        if (list == null || list.isEmpty()) {
            list = vaccinationTypeDao.selectAllVaccinationTypeById();
            RedisUtils.setValueTimeout(key, list, 24 * 3600);
        }
        return list;
    }

    @Override
    public VaccinationType selectVaccinationById(Integer id) {
        VaccinationType vaccinationType = vaccinationTypeDao.selectById(id);
        return vaccinationType;
    }

    @Override
    public void insert(VaccinationTypeParam param) {
        VaccinationType vaccinationType = new VaccinationType();
        BeanUtils.copyProperties(param,vaccinationType);
        vaccinationTypeDao.insert(vaccinationType);
    }
}
